from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import viewsets, mixins
from rest_framework.filters import SearchFilter, OrderingFilter

from home.models import Category
from home.serializers import CategorySerializer


@extend_schema_view(
    list=extend_schema(summary='获取分类列表', tags=['分类'], description='获取分类列表'),
    # create=extend_schema(summary='新增分类',tags=['分类'],description='新增分类'),
    # retrieve=extend_schema(summary='获取单条分类详情',tags=['分类'],description='获取单条分类详情'),
    # update=extend_schema(summary='更新分类(全量更新)',tags=['分类'],description='更新分类(全量更新)'),
    # partial_update=extend_schema(summary='更新分类(部分更新)',tags=['分类'],description='更新分类(部分更新)'),
    # destroy=extend_schema(summary='删除分类',tags=['分类'],description='删除分类')
)
class CategoryViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
    # 设置数据集
    queryset = Category.objects.all()
    # 设置序列化器
    serializer_class = CategorySerializer
    # 禁用分页功能
    pagination_class = None
    filter_backends = (SearchFilter, OrderingFilter,)
    search_fields = ['name']
    ordering_fields = ['id']
